# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=freeglut
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pre=
_ver=3.0.0
pkgver=${_ver}${_pre}
pkgrel=3
pkgdesc="Freeglut allows the user to create and manage windows containing OpenGL contexts (mingw32-w64)"
arch=('any')
url="http://freeglut.sourceforge.net/"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('strip' '!libtool' 'staticlibs')
source=("https://downloads.sourceforge.net/freeglut/${_realname}-${_ver}${_pre}.tar.gz"
        "0001-Emit-the-correct-LIBNAME-to-.pc-files.patch")
sha256sums=('2a43be8515b01ea82bcfa17d29ae0d40bd128342f0930cd1f375f1ff999f76a2'
            '2a4409366ed6661695cb2ce8cfb0084f0e337d76116d16d507945fa5f2d67cd3')
noextract=(${_realname}-${_ver}${_pre}.tar.gz)

prepare() {
  # Clean up old sources so re-patching doesn't fail.
  [[ -d ${srcdir}/${_realname}-${_ver}${_pre} ]] && rm -rf ${srcdir}/${_realname}-${_ver}${_pre}
  tar -xzvf ${_realname}-${_ver}${_pre}.tar.gz -C ${srcdir}
  # Upstreaming at https://github.com/dcnieho/FreeGLUT/pull/41
  cd ${_realname}-${_ver}${_pre}
  patch -p3 -i "${srcdir}"/0001-Emit-the-correct-LIBNAME-to-.pc-files.patch
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    ../${_realname}-${_ver}${_pre}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
